﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAPbobsCOM;
using System.Reflection;
using System.Runtime.Serialization;

namespace CompanySyncProject
{
    public class DIService : BaseRun
    {
        public DIService(Company co, System.IO.StreamWriter lo)
            : base(co, lo)
        {

        }

        public override void Run()
        {
            SAPbobsCOM.GeneralService oGeneralService;
            SAPbobsCOM.GeneralData oGeneralData;
            SAPbobsCOM.GeneralData oGeneralDataXML;
            string XMLString;

            Hashtable Properties = new Hashtable();
            Properties["CardCode"] = "new2";
            Properties["CardName"] = "new name 2";

            oGeneralService = oCompany.GetCompanyService().GetGeneralService("BusinessPartnersService");
            oGeneralData = (GeneralData)oGeneralService.GetDataInterface(GeneralServiceDataInterfaces.gsGeneralData);

            foreach (DictionaryEntry Pair in Properties)
                oGeneralData.SetProperty(Pair.Key.ToString(), Pair.Value.ToString());

            XMLString = oGeneralData.ToXMLString();

            //Retrieve XML string and create GeneralData object from the XML  
            oGeneralDataXML = (GeneralData)oGeneralService.GetDataInterfaceFromXMLString(XMLString);
            //oGeneralService.Add(oGeneralDataXML); 
            oGeneralService.DoCommand(oGeneralDataXML, "201");
        }
    }
}
